import $getScript from './getScript'

export const getJavascriptExif = () => {
	return new Promise((resolve) => {
		const options = {
			src: '//s.yangshipin.cn/CCTVVideo/CCTVVideoAssets/v10/js/exif.js',
			onLoad: () => {
				resolve()
			}
		}
		if (window.EXIF) {
			resolve()
		} else {
			$getScript(options)
		}
	})
}

export const getOrientation = async (file) => {
	await getJavascriptExif()
	return new Promise((resolve, reject) => {
		// eslint-disable-next-line no-undef
		EXIF.getData(file, function() {
			// eslint-disable-next-line no-undef
			EXIF.getAllTags(this)
			// eslint-disable-next-line no-undef
			const Orientation = EXIF.getTag(this, 'Orientation')
			resolve(Orientation)
		})
	})
}
